<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>借书管理界面</title>
    <script src="https://lib.sinaapp.com/js/jquery/3.1.0/jquery-3.1.0.js"></script>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>

    <style>
        td:nth-child(2) {
            table-layout: fixed;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        td:nth-child(5) {
            table-layout: fixed;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        td:nth-child(3) {
            table-layout: fixed;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        td:nth-child(8) {
            table-layout: fixed;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>

    <script>
        function deleteConfirm(borrowID) {
            if (window.confirm("确定删除该条申请记录吗？")) {
                document.location.href =
                    "${pageContext.request.contextPath}/borrow/deleteApply?borrowID=" + borrowID;
            }
        }

        function deleteMyConfirm(borrowID) {
            if (window.confirm("确定删除该条申请记录吗？")) {
                document.location.href =
                    "${pageContext.request.contextPath}/borrow/deleteMyApply?borrowID=" + borrowID;
            }
        }

        function returnConfirm(borrowID) {
            if (window.confirm("确定还这本书吗？")) {
                document.location.href =
                    "${pageContext.request.contextPath}/borrow/approveApply?borrowStatus=returned&borrowID=" + borrowID;
            }
        }
    </script>
</head>
<body>
<div class="row" style="margin-top: 15px;">
    <h1 style="font-family: 'YouYuan'; color: rgb(0, 85, 255);" id="title" class="col-sm-10 col-sm-offset-1">
        <c:if test="${sessionScope.userMessage.authority != 'general'}">
            借书申请管理:
        </c:if>
        <c:if test="${sessionScope.userMessage.authority == 'general'}">
            我的借书申请：
        </c:if>
    </h1>
</div>

<div class="container">
    <div class="row clearfix" style="margin-top: 30px;">
        <div class="col-md-4 column">
            <a class="btn btn-warning" href="${pageContext.request.contextPath}/book/query">返回</a>
            <c:if test="${queryMessage != null}">
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/borrow/toAllBorrow">回到主页面</a>
            </c:if>
        </div>
        <c:if test="${sessionScope.userMessage.authority != 'general'}">
            <div class="col-lg-8 column text-right">
                <form action="${pageContext.request.contextPath}/borrow/queryApply" class="form-inline">
                    <div class="form-group">
                        <span style="color: red; font-weight: bold">${queryMessage}</span>
                        <input class="form-control" placeholder="请输入要查询的邮箱" autocomplete="off" id=""
                               name="borrowerEmail"
                               required>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary">查询</button>
                    </div>
                </form>
            </div>
        </c:if>
    </div>
</div>
<div class="row">
    <div class="col-sm-8 col-sm-offset-2">
        <table id="dataTable" class="table table-hover table-bordered table-striped table-condensed "
               style="margin-top: 15px;">
            <thead>
            <tr class="info">
                <th style="text-align: center;">申请序号</th>
                <th style="text-align: center;">租借人</th>
                <th style="text-align: center;">书籍名称</th>
                <th style="text-align: center;">租赁金额</th>
                <th style="text-align: center;">开始日期</th>
                <th style="text-align: center;">申请时长(天)</th>
                <th style="text-align: center;">借书状态</th>
                <th style="text-align: center;">操作</th>
            </tr>
            </thead>
            <c:forEach items="${borrowVOList}" var="apply" varStatus="applyStatus">
                <tr style="text-align: center">
                    <td>${applyStatus.count}</td>
                    <td>${apply.userName}</td>
                    <td>${apply.bookName}</td>
                    <td>${apply.cost}</td>
                    <td>${apply.beginDate}</td>
                    <td>${apply.duration}</td>
                    <td>
                        <c:choose>
                            <c:when test="${apply.borrowStatus == 'prepared'}">
                                <p class="bg-warning">审批中</p>
                            </c:when>
                            <c:when test="${apply.borrowStatus == 'accepted'}">
                                <p class="bg-success">已通过</p>
                            </c:when>
                            <c:when test="${apply.borrowStatus == 'refused'}">
                                <p class="bg-danger">已拒绝</p>
                            </c:when>
                            <c:when test="${apply.borrowStatus == 'returned'}">
                                <p class="bg-primary">已还书</p>
                            </c:when>
                            <c:otherwise>
                                <p class="bg-danger">错误！</p>
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <c:if test="${sessionScope.userMessage.authority != 'general'}">
                            <a class="btn btn-info btn-sm"
                               href="${pageContext.request.contextPath}/borrow/approveApply?borrowStatus=accepted&borrowID=${apply.borrowID}">同意</a>
                            &nbsp;
                            <a class="btn btn-info btn-sm"
                               href="${pageContext.request.contextPath}/borrow/approveApply?borrowStatus=refused&borrowID=${apply.borrowID}">拒绝</a>
                            &nbsp;
                            <a class="btn btn-warning btn-sm" href="javascript:void(0);"
                               onclick="returnConfirm('${apply.borrowID}')">还书</a>
                            &nbsp;
                            <a class="btn btn-danger btn-sm" href="javascript:void(0);"
                               onclick="deleteConfirm('${apply.borrowID}')">删除</a>
                        </c:if>
                        <c:if test="${sessionScope.userMessage.authority == 'general'}">
                            <a class="btn btn-danger btn-sm" href="javascript:void(0);"
                               onclick="deleteMyConfirm('${apply.borrowID}')">删除</a>
                        </c:if>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </div>
</div>
</body>
</html>
